using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Microsoft.Practices.WizardFramework;
using VSSDKAssist.Assets.CustomPages;
using VSSDKAssist.Recipes.Common.Editors;
using VSSDKAssist.Recipes.Common.Converters;
using EnvDTE;
using VSSDKAssist.Assets.Helpers;
using VSSDKAssist.Enums;
using Microsoft.VisualStudio.Shell;

namespace VSSDKAssist.Recipes.CreateVSPackageDeploymentInfo
{
	/// <summary>
	/// Custom page for CreateVSPackageDeploymentInfoCP recipe
	/// </summary>
	public partial class CreateVSPackageDeploymentInfoCP : WizardPageBase
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="CreateVSPackageDeploymentInfoCP"/> class.
		/// </summary>
		public CreateVSPackageDeploymentInfoCP()
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="CreateVSPackageDeploymentInfoCP"/> class.
		/// </summary>
		/// <param name="wizard">The <see cref="T:Microsoft.Practices.WizardFramework.WizardForm"/>that will host the new page.</param>
		public CreateVSPackageDeploymentInfoCP(WizardForm wizard)
			: base(wizard)
		{
			InitializeComponent();
		}

		/// <summary>
		/// Gets or sets the deployment info.
		/// </summary>
		/// <value>The deployment info.</value>
		[RecipeArgument]
		public DeploymentInfo DeploymentInformation
		{
			get { return (DeploymentInfo)veDeploymentInfo.Value; }
			set
			{
				veDeploymentInfo.TextBox.Text = value.ToString();
			}
		}

		/// <summary>
		/// Gets or sets the registration method.
		/// </summary>
		/// <value>The registration method.</value>
		[RecipeArgument]
		public RegistrationMethod RegistrationMethod
		{
			get { return (RegistrationMethod)veRegistrationMethod.Value; }
			set
			{
				veRegistrationMethod.TextBox.Text = value.ToString();
			}
		}

		/// <summary>
		/// Gets or sets the site of the control.
		/// </summary>
		/// <value></value>
		/// <returns>The <see cref="T:System.ComponentModel.ISite"></see> associated with the <see cref="T:System.Windows.Forms.Control"></see>, if any.</returns>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet>
		public override ISite Site
		{
			get
			{
				return base.Site;
			}
			set
			{
				base.Site = value;
				if(value != null)
				{
					this.veRegistrationMethod.BeginInit();
					this.veRegistrationMethod.ValueType = typeof(RegistrationMethod);
					base.Site.Container.Add(veRegistrationMethod);
					this.veRegistrationMethod.ConverterInstance = new EnumConverter(typeof(RegistrationMethod));
					this.veRegistrationMethod.EndInit();

					this.veDeploymentInfo.BeginInit();
					this.veDeploymentInfo.ValueType = typeof(DeploymentInfo);					
					base.Site.Container.Add(veDeploymentInfo);
					this.veDeploymentInfo.ConverterInstance = new EnumConverter(typeof(DeploymentInfo));
					this.veDeploymentInfo.EndInit();
				}
			}
		}

		private void veDeploymentInfo_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			DeploymentInfo deploymentInfo = (DeploymentInfo)veDeploymentInfo.Value;
			DictionaryService.SetValue("DeploymentInformation", deploymentInfo);
		}

		private void veRegistrationMethod_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			RegistrationMethod registrationMethod = (RegistrationMethod)veRegistrationMethod.Value;
			DictionaryService.SetValue("RegistrationMethod", registrationMethod);
		}
	}
}